// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf

#include "MgcMaterialState.h"

MgcImplementRTTI(MgcMaterialState,MgcRenderState);
MgcImplementStream(MgcMaterialState);
MgcImplementDefaultState(MgcMaterialState);

//----------------------------------------------------------------------------
MgcRenderState::Type MgcMaterialState::GetType () const
{
    return RS_MATERIAL;
}
//----------------------------------------------------------------------------
MgcMaterialState::MgcMaterialState ()
    :
    m_kEmissive(MgcColor::BLACK),
    m_kAmbient(0.2,0.2,0.2),
    m_kDiffuse(0.8,0.8,0.8),
    m_kSpecular(MgcColor::BLACK)
{
    m_fShininess = 0.0;
    m_fAlpha = 1.0;
}
//----------------------------------------------------------------------------

//---------------------------------------------------------------------------
// streaming
//---------------------------------------------------------------------------
MgcObject* MgcMaterialState::Factory (MgcStream& rkStream)
{
    MgcMaterialState* pkObject = new MgcMaterialState;
    MgcStream::Link* pkLink = new MgcStream::Link(pkObject);
    pkObject->Load(rkStream,pkLink);
    return pkObject;
}
//---------------------------------------------------------------------------
void MgcMaterialState::Load (MgcStream& rkStream, MgcStream::Link* pkLink)
{
    MgcRenderState::Load(rkStream,pkLink);

    // native data
    MgcStreamRead(rkStream,m_kEmissive);
    MgcStreamRead(rkStream,m_kAmbient);
    MgcStreamRead(rkStream,m_kDiffuse);
    MgcStreamRead(rkStream,m_kSpecular);
    MgcStreamRead(rkStream,m_fShininess);
    MgcStreamRead(rkStream,m_fAlpha);
}
//---------------------------------------------------------------------------
void MgcMaterialState::Link (MgcStream& rkStream, MgcStream::Link* pkLink)
{
    MgcRenderState::Link(rkStream,pkLink);
}
//---------------------------------------------------------------------------
bool MgcMaterialState::Register (MgcStream& rkStream)
{
    return MgcRenderState::Register(rkStream);
}
//---------------------------------------------------------------------------
void MgcMaterialState::Save (MgcStream& rkStream)
{
    MgcRenderState::Save(rkStream);

    // native data
    MgcStreamWrite(rkStream,m_kEmissive);
    MgcStreamWrite(rkStream,m_kAmbient);
    MgcStreamWrite(rkStream,m_kDiffuse);
    MgcStreamWrite(rkStream,m_kSpecular);
    MgcStreamWrite(rkStream,m_fShininess);
    MgcStreamWrite(rkStream,m_fAlpha);
}
//---------------------------------------------------------------------------
